<script lang="ts" setup>
import { computed, inject, Ref } from 'vue'
interface Props {
  activeValue: string | boolean
  inactiveValue: string | boolean
  disabled?: boolean
}
const props = withDefaults(defineProps<Props>(), {
  disabled: false
})
const buttonValue = inject('buttonValue') as Ref<string | boolean>
const isActive = computed(() => buttonValue.value === props.activeValue)
const handleClick = () => {
  if (buttonValue.value === props.activeValue) {
    buttonValue.value = props.inactiveValue
  } else {
    buttonValue.value = props.activeValue
  }
}
</script>

<template>
  <button
    class="custom-active-button"
    :class="{ 'is-active': isActive, 'is-disabled': disabled }"
    @click="handleClick"
    :disabled="disabled"
  >
    <slot />
  </button>
</template>

<style scoped lang="scss">
.custom-active-button {
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px solid var(--xy-light-color);
  border-radius: 4px;
  color: #909399;
  font-weight: 500;
  font-size: 12px;
  width: 60px;
  padding: 8px 12px;
  box-sizing: border-box;
  line-height: 1;
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  white-space: nowrap;
  margin-right: 10px;
  cursor: pointer;
  background: #fff;
}
.custom-active-button:hover {
  color: var(--el-text-color-regular);
  border-color: var(--xy-primary-light-color);
}
.custom-active-button.is-active {
  border-color: transparent;
  background-color: var(--xy-primary-light-color);
  color: var(--xy-primary-color);
}
.custom-active-button.is-disabled {
  color: #e4e7ed;
  cursor: not-allowed;
}
</style>
